#!/usr/bin/python
# -*- coding: UTF-8 -*-

from dbm import *

########## 数据库表业务函数

# ##### tbl_oss_sp_activity_info
# class ActivityInfo(DBTable):
#     def __init__(self, tbname):
#         DBTable.__init__(self, tbname)
#     def findby_tid_name(self, tid, name):
#         sql = 'SELECT `'+name+'` FROM '+self.tbname+' WHERE `tid`=%s'
#         pms = (tid,)
#         return M.fetch_all(sql, pms)
#     def updateby_tid_name(self, tid, name, val):
#         sql = self._select() + 'WHERE `tid`=%s'
#         pms = (tid,)
#         return M.fetch_all(sql, pms)
# activity_info = ActivityInfo('tbl_oss_sp_activity_info')

##### tbl_oss_sp_code_date
class CodeDate(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
    def findby_tid(self, tid):
        sql = self._select() + 'WHERE `tid`=%s'
        pms = (tid,)
        return M.fetch_all(sql, pms)
    def deleteby_tid(self, tid):
        sql = self._delete() + 'WHERE `tid`=%s'
        pms = (tid,)
        return M.save_or_update(sql, pms)
code_date = CodeDate('tbl_oss_sp_code_date')

##### tbl_oss_sp_code_ver
class CodeVer(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
    def findby_tid(self, tid):
        sql = self._select() + 'WHERE `tid`=%s'
        pms = (tid,)
        return M.fetch_all(sql, pms)
    def deleteby_tid(self, tid):
        sql = self._delete() + 'WHERE `tid`=%s'
        pms = (tid,)
        return M.save_or_update(sql, pms)
code_ver = CodeVer('tbl_oss_sp_code_ver')

##### tbl_oss_sp_commu_contri_level
class CommuContriLevel(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
    def findby_tid(self, tid):
        sql = self._select() + 'WHERE `tid`=%s'
        pms = (tid,)
        return M.fetch_all(sql, pms)
commu_contri_level = CommuContriLevel('tbl_oss_sp_commu_contri_level')

##### tbl_oss_sp_commu_src
class CommuSrc(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
commu_src = CommuSrc('tbl_oss_sp_commu_src')

##### tbl_oss_sp_commu_sta
class CommuSta(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
    def findby_tid(self, tid):
        sql = self._select() + 'WHERE `tid`=%s'
        pms = (tid,)
        return M.fetch_all(sql, pms)
commu_sta = CommuSta('tbl_oss_sp_commu_sta')

##### tbl_oss_sp_project_inf
class ProjectInf(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
    def findby_tid_key(self, tid, key):
        sql = self._select() + 'WHERE `tid`=%s AND `key_name` LIKE %s'
        pms = (tid, key + '%')
        return M.fetch_all(sql, pms)
project_inf = ProjectInf('tbl_oss_sp_project_inf')

##### tbl_oss_sp_se_info
class SeInfo(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
    def findby_tid(self, tid):
        sql = self._select() + 'WHERE `tid`=%s'
        pms = (tid,)
        return M.fetch_all(sql, pms)
se_info = SeInfo('tbl_oss_sp_se_info')

##### tbl_oss_sp_task_record
class TaskRecord(DBTable):
    def __init__(self, tbname):
        DBTable.__init__(self, tbname)
task_record = TaskRecord('tbl_oss_sp_task_record')
